﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace A2DFramework.EsbService.NativeEsb.Configuration
{
    static class NativeEsbConfiguration
    {
        public static Dictionary<string, Type> CommandHandlerMappings = new Dictionary<string, Type>();

        static NativeEsbConfiguration()
        {
            //load setings from xml file
            XElement root = XElement.Load(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "A2D.config"));

            root = root.Element("EsbSetting");
            if (root == null)
                throw new Exception("EsbSetting node not exists");

            foreach (var node in root.Element("NativeEsb").Elements("CommandHandlerMapping"))
            {
                Type handlerType=Type.GetType(node.Attribute("CommandHandlerType").Value, true);
                CommandHandlerMappings[node.Attribute("CommandType").Value] = handlerType;
            }
        }
    }
}
